package com.panshi.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2 //开启swagger2
public class SwaggerConfig {


    //    配置swagger docket的bean实例
//    Environment 可以查看是什么环境
    @Bean
    public Docket docket(Environment environment) {

//        设置要显示的环境
        Profiles of = Profiles.of("dev", "hello");
//        判断是否开启
        boolean b = environment.acceptsProfiles(of);
        Docket docket = new Docket(DocumentationType.SWAGGER_2)

//enabled 是否启动swaggerWeb
                .apiInfo(apiInfo())
                .groupName("zhlMr")
                .enable(b)
                .select()
                //配置扫描接口的方法
//                any扫描全部
//                none全部都不扫描
//                扫描类上的注解withClassAnnotation
//withMethodAnnotation扫描方法上注解
//                path过滤啥路径
                .apis(RequestHandlerSelectors.basePackage("com.panshi.controller"))
                .build();
        return docket;
    }


    //    配置多个docket 相当于多个环境配置
    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("docket1");
    }


    //配置swagger api信息 =  apiInfo
    public ApiInfo apiInfo() {
//        作者信息
        Contact DEFAULT_CONTACT = new Contact("xhlMr", "https://user.qzone.qq.com/1685331320", "1685331320@qq.com");
        return new ApiInfo(
                "xhlMr _ 日志",
                "努力成为码农",
                "v1.0",
                "https://user.qzone.qq.com/1685331320",
                DEFAULT_CONTACT,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
